package networkSimulation.visualisation.graph.graphviz;

import java.io.File;

public class Visualiser  {
   
   private int counter;   

    public Visualiser(){
        counter = 0;
    }

   public void saveGraph(String nodes, String edges, String outputPath){
       GraphViz gv = new GraphViz();
       gv.addln(gv.start_graph());
       gv.addln("size =\"10,5\"");
       gv.addln("ratio=fill");
       String[] nodez = nodes.split(";");
        for (String node : nodez)
            if(!(node.trim().equals("")))
                gv.addln("node " + node);
       String[] edgez = edges.split(";");
        for (String edge : edgez)
            if(!(edge.trim().equals("")))
                gv.addln(edge);
       gv.addln(gv.end_graph());
       String type = "gif";
       File out = new File(outputPath + counter++ + "." + type);
       gv.writeGraphToFile( gv.getGraph( gv.getDotSource(), type ), out );
   }

    /**
     *   examples:
     *
     *   gv.addln("N1 -> N2[dir=both color=\"black:red\"];");
     *   gv.addln("N4 -> N2;");
     *   gv.addln("N1 -> N8[dir=both];");
     *   gv.addln("N6 -> N7[color=black];");
      */

}
